using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using System.ComponentModel;
using System.Security.Permissions;
using System.IO;

namespace SharePointing.Features.MetaTags.Controls
{
    /// <summary>
    /// This control renders the actual metatags out to the page
    /// where the control is placed. This Control is much more powerful than the basic METATAG
    /// control that is included here as it allows you to manage all of your MetaTags for the site
    /// in a single place and then define ADDITIONS to the metaTags at the page level
    /// 
    /// Reads from the MetaTags List to get the "Global" Tags
    /// then reads from the CHK_MetaTag field on the page to append the
    /// tags for the specific page if there are any defined.
    /// </summary>
    [ParseChildren(false), ToolboxData("<{0}:MetaTagRenderControl runat=\"server\" name=\"\"> </{0}:MetaTagRenderControl>"), PersistChildren(true),
    AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class MetaTagRenderControl : WebControl
    {
        protected string m_Name = "";
        protected string m_Value = "";
        
        public MetaTagRenderControl() : base(HtmlTextWriterTag.Meta)
        {
        
        }

        
        protected override void Render(HtmlTextWriter writer)
        {
            // Render control only if there is a tagname specified
            if (!m_Name.Equals(string.Empty))
                base.Render(writer);
        }
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            // Write the name attribute
            writer.AddAttribute("name", m_Name);

            // Write the value attribute
            StringWriter sw = new StringWriter();
            base.RenderContents(new HtmlTextWriter(sw));
            writer.AddAttribute("value", sw.ToString());
            // the metata does not have any other attributes that could be rendered: don't call base...
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            // Read in the Defaults from the MetaTag List

            // Read in the options for this page

            // Merge the Optionals with the Defaults.

            // Render the output to the page


        } 

    }
}
